package com.lixianbiao;

/**
 * 191. 位1的个数
 *
 * @author lixianbiao
 * @since 2024/06/04 14:29
 */
public class OneCount {
    public static int getOneCount(int n){
        int count = 0;
        while(n != 0){
            count = count + 1;
            n = n & (n -1);
        }
        return count;
    }
    public static void main(String[] args) {
        int n = 8;
        System.out.println(n+"的二进制:"+Integer.toBinaryString(n));
        System.out.println("getOneCount(n) = " + getOneCount(n));
    }
}